package com.dhwl.hsh.merchant.ui.activity;

import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;

import com.dhwl.hsh.lib.constant.GlobalConfig;
import com.dhwl.hsh.lib.utils.PreferenceHelper;
import com.dhwl.hsh.merchant.R;
import com.dhwl.hsh.merchant.common.Constant;

/**
 * 启动页面
 *
 * @author Derek.Kidd
 * @time 2016/4/14 16:14
 */
public class StartUpActivity extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_start_up;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {

    }

    @Override
    protected void initData() {
        //版本更新

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                // 不存在该值返回true
                boolean isFrist = PreferenceHelper.readBoolean(StartUpActivity.this, Constant.GLOBAL_PREFERENCE_FILE, "is_first_start_app", true);
                Intent intent = new Intent();
                if (isFrist) {
                    PreferenceHelper.write(StartUpActivity.this, Constant.GLOBAL_PREFERENCE_FILE, "is_first_start_app", false);
                    intent.setClass(StartUpActivity.this, GuideActivity.class);

                } else {
                    if (GlobalConfig.getInstance().isLogin()) {
                        intent.setClass(StartUpActivity.this, MainActivity.class);
                    } else {
                        intent.setClass(StartUpActivity.this, LoginActivity.class);
                    }
                }
                startActivity(intent);
                finish();

            }
        }, 2000);
    }


    @Override
    protected void onResume() {
        super.onResume();

        //防止系统设置字体放大
        Resources resource = getResources();
        Configuration c = resource.getConfiguration();
        c.fontScale = 1.0f;
        resource.updateConfiguration(c, resource.getDisplayMetrics());
    }

}
